package com.emc.elc.rabbitmq.wapper.Handler;

import java.util.HashMap;
import java.util.Map;

import com.rabbitmq.client.AMQP.BasicProperties;

public abstract class MessageIdCompareHandler implements MessageHandler {
    protected Map<String, MessageHandler> messageHandlers = new HashMap<String, MessageHandler>();
    @Override
    public void handle(String msg, String routingKey, BasicProperties basicProperties) {
        for (String message:messageHandlers.keySet()) {
            if (compare(basicProperties.getMessageId(), message)) {
                messageHandlers.get(message).handle(msg, routingKey, basicProperties);
            }
        }
    }
    
    public void bindMessageHandlerToMessageId (String messageContent, MessageHandler messageHandler) {
        messageHandlers.put(messageContent, messageHandler);
    }
    
    protected abstract boolean compare(String messageId, String bindMessageId);
}
